package classes;

/**
 * Point.java
 * 
 * @author Nicole Nelson
 */
public class Point 
{
	private int xCord;
	private int yCord;
	
	/*
	 * Constructor: Sets X and Y Coordinates to passed in values
	 */
	public Point(int x, int y)
	{
		setX(x);
		setY(y);
	}
	
	/*
	 * Returns X Coordinate
	 */
	public int getX()
	{
		return xCord;
	}
	
	/*
	 * Sets X Coordinate
	 */
	public void setX(int xNew)
	{
		xCord = xNew;
	}
	
	/*
	 * Returns Y Coordinate
	 */
	public int getY()
	{
		return yCord;
	}
	
	/*
	 * Sets Y Coordinate
	 */
	public void setY(int yNew)
	{
		yCord = yNew;
	}
	
	/*
	 * Gets distance between the two points
	 * Using the formula Sqrt((x2 - x1)^2 + (y2 - y1)^2)
	 */
	public double calcDistance(Point p)
	{
		double distance = 0;
		double left = Math.pow((p.getX() - getX()), 2);
		double right = Math.pow((p.getY() - getY()), 2);
		distance = Math.sqrt(left + right);
		return distance;		
	}
	
	/*
	 * Determines if the three points are a right angle with this as the center
	 * Uses the Pythagorean theorem c^2 = a^2 + b^2
	 */
	public boolean isRightAngle(Point two, Point three, int MOE)
	{
		boolean result = false;
		double calcEstD = Math.sqrt(Math.pow(calcDistance(two), 2) + Math.pow(calcDistance(three), 2));
		double actD = two.calcDistance(three);
		
		if (calcEstD <= actD + MOE && calcEstD >= actD - MOE)
			result = true;
		return result;
	}
	
	
	/*
	 * Determines if the triangle is a right triangle and if so returns which point is the center
	 * if not a right triangle returns null
	 */
	public Point findCenter(Point two, Point three)
	{
		int MOE = 8;
		if(this.isRightAngle(two, three, MOE))
			return this;
		if(two.isRightAngle(this, three, MOE))
			return two;
		if(three.isRightAngle(this, two, MOE))
			return three;
		else
			return null;
	}
}
